<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/23
  Time: 13:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<nav class="navbar-default navbar-static-side" role="navigation">
    <div class="sidebar-collapse">
        <ul class="nav metismenu" id="side-menu">
            <li class="nav-header">
                <div class="dropdown profile-element"> <span>
                            <img alt="image" class="img-circle" src="img/head.jpg" style="width:48px;height:48px;"/>
                             </span>
                    <a data-toggle="dropdown" class="dropdown-toggle" href="index.jsp#">
                            <span class="clear"> <span class="block m-t-xs"> <strong
                                    class="font-bold" id="userClass">${user.name}</strong>
                             </span> <span class="text-muted text-xs block" id="roleclass">
                                <c:if test="${user.role==0}">管理员</c:if>
                                <c:if test="${user.role==1}">第三方</c:if>
                                <b class="caret"></b></span> </span> </a>
                    <ul class="dropdown-menu animated fadeInRight m-t-xs">
                        <li><a data-toggle="modal" data-target="#changePwdM" class="glyphicon glyphicon-lock">修改密码</a></li>
                        <li class="divider"></li>
                        <li><a href="logout" class="glyphicon glyphicon-log-out">登出</a></li>
                    </ul>
                </div>
                <div class="logo-element">
                    <img src="img/huawei.png" style="width:70px;height:60px;">
                </div>
            </li>
            <c:forEach items="${menu}" var="m">
                <c:if test="${m.pid==0}">
                    <li>
                        <a href="${m.link}"><i class="${m.icon}"></i> <span class="nav-label">${m.name}</span><span
                                class="fa arrow"></span></a>
                        <ul class="nav nav-second-level collapse">
                            <c:forEach items="${menu}" var="sm">
                                <c:if test="${sm.pid==m.id}">
                                    <li><a href="${sm.link}" class="${sm.icon}">${sm.name}</a></li>
                                </c:if>
                            </c:forEach>
                        </ul>
                    </li>
                </c:if>
            </c:forEach>
            </a>
            <li class="special_link">
                <a href="index.jsp"><i class="fa fa-magic"></i> <span class="nav-label">CSS Animations </span><span
                        class="label label-info pull-right">62</span></a>
            </li>
            <li>
                <a><i class="fa fa-database"></i> <span class="nav-label">Package</span><span
                        class="label label-warning pull-right">NEW</span></a>
            </li>
        </ul>
    </div>
</nav>

<div id="small-chat" style="bottom: 40px
">
    <span class="badge badge-warning pull-right"></span>
    <a class="open-small-chat" href="index.jsp">
        <i class="glyphicon glyphicon-home"></i>
    </a>
</div>

<div class="modal fade" id="changePwdM" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改密码</h4>
            </div>
            <div class="modal-body">
                <form id="changePwd">
                    <div class="form-group ">
                        <input type="hidden" class="form-control" id="uid" name="uid" placeholder="Email"
                               value="${user.id}" required="">
                    </div>
                    <div class="form-group">
                        <label for="pwdOld">原密码</label>
                        <input type="password" class="form-control" id="pwdOld" name="pwdOld" placeholder="原密码"
                               required="">
                    </div>
                    <div class="form-group">
                        <label for="pwdNew">新密码</label>
                        <input type="password" class="form-control" id="pwdNew" name="pwdNew" placeholder="新密码"
                               required="">
                    </div>
                    <div class="form-group">
                        <label for="pwdNewCof">确认密码</label>
                        <input type="password" class="form-control" id="pwdNewCof" name="pwdNewCof" placeholder="确认密码"
                               required="">
                    </div>
                    <button type="button" class="btn btn-danger" onclick="append()">确认修改</button>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script>
    function append() {
        var d = $("#changePwd").serialize();
        // console.log(d)
        var url = "changePwd?" + d;
        $.post(url, {}, function (data) {
            console.log(data);
            if (data == 1) {
                swal('输入有误', "新密码或旧密码未输入", 'error');
            }
            if (data == 2) {
                swal('输入有误', "两次输入密码不符", 'error');
            }
            if (data == 3) {
                swal('成功', "修改成功，下次登录生效", 'success');
                setTimeout(function () {
                    window.location.href = "logout"
                }, 1000);
            }
            if (data == 6) {
                swal('失败', "原密码与现密码相同", 'error');
            }
            if (data == 4) {
                swal('出错了', "密码修改失败，请稍后再试", 'error');
            }
            if (data == 5) {
                swal("密码错误", "原密码有误", "error")
            }
        })
    }
</script>

<script>
   $(function() {setUnM()})

   function setUnM(){
       $.post("user/editByIdGet",{
           "id":${user.id},
           "conf":"true"
       },function (data){
           console.log("主页方法");
           // console.log(data);
           $("#userClass").html(data.user.name);
     if (data.user.role==0){
         $("#roleclass").html("管理员");
     }else{
         $("#roleclass").html("第三方");
     }
       },"json"
   )
   }
</script>